local souying = fk.CreateSkill {

  name = "joy__souying",

  tags = {  },

}



souying:addEffect(fk.TargetSpecified, {
  name = "joy__souying",
  mute = true,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(souying.name) and not player:isNude() and player:usedSkillTimes(souying.name, Player.HistoryTurn) == 0 and
    (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) and #data:getAllTargets() == 1 then
      local room = player.room
      local events = {}
      if target == player then
        if data.to == player.id or room:getCardArea(data.card) ~= Card.Processing then return false end
        return true
      else
        if data:getAllTargets()[1] ~= player.id then return false end
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local prompt
    if target == player then
      prompt = "#souying1-invoke:::"..data.card:toLogString()
    else
      prompt = "#souying2-invoke:::"..data.card:toLogString()
    end
    local card = player.room:askForDiscard(player, 1, 1, true, souying.name, true, ".", prompt, true)
    if #card > 0 then
      event:setCostData(self, card)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(event:getCostData(self), souying.name, player, player)
    player:broadcastSkillInvoke(souying.name)
    if target == player then
      room:notifySkillInvoked(player, souying.name, "drawcard")
      if not player.dead and room:getCardArea(data.card) == Card.Processing then
        room:obtainCard(player, data.card, true, fk.ReasonJustMove)
      end
    else
      room:notifySkillInvoked(player, souying.name, "defensive")
      table.insertIfNeed(data.nullifiedTargets, player.id)
    end
  end,
})

return souying